package com.example;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

public class CodeGenerator {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/productionmanagesystem?useSSL=false&serverTimezone=Asia/Shanghai";
        String username = "root";
        String password = "1234";

        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> builder
                        .outputDir(System.getProperty("user.dir") + "/src/main/java")
                        .disableOpenDir() // 生成后不打开目录
                )
                .packageConfig(builder -> builder
                        .parent("com.example")
                        .entity("domain.entity")
                        .mapper("mapper")
                        .service("service")
                        .controller("controller")
                )
                .strategyConfig(builder -> builder
                        .addInclude("material_purchase") // 指定表名
                        .addTablePrefix("t_") // 过滤表前缀
                        .entityBuilder().enableLombok() // 启用Lombok
                        .controllerBuilder().enableRestStyle() // REST风格Controller
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}